package com.jingan.nursinghome.regulatory.dialog2;

import android.graphics.Rect;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.jingan.nursinghome.regulatory.R;
import com.jingan.nursinghome.regulatory.adapter.RichangAdapter;
import com.jingan.nursinghome.regulatory.data.MicrometerTable;
import com.jingan.nursinghome.regulatory.dialog.MicrometerTableOSDialog;
import com.jingan.nursinghome.regulatory.view.MyActionBar;
import com.jingan.nursinghome.regulatory.view.MySpacesItemDecoration;

import cn.android.support.v7.lib.sin.crown.base.BaseActivity;
import cn.android.support.v7.lib.sin.crown.base.BaseDialog;
import cn.android.support.v7.lib.sin.crown.base.BaseListenner;
import cn.android.support.v7.lib.sin.crown.utils.ProportionUtils;

/**
 * Created by 彭治铭 on 2017/10/24.
 */

public class RichangDialog2 extends BaseDialog {
    public RichangDialog2(BaseActivity baseActivity) {
        init(baseActivity, R.layout.dialog_richang2, false, false);
        window.setWindowAnimations(cn.android.support.v7.lib.sin.crown.R.style.Crown_Window_right);
        initUI();
        adapterUI();
    }

    public static RichangDialog2 richangDialog2;

    public static RichangDialog2 getInstance(BaseActivity baseActivity) {
        if (isFinishing(richangDialog2)) {
            richangDialog2 = new RichangDialog2(baseActivity);
        }
        return richangDialog2;
    }

    MyActionBar myActionBar;
    TextView appraise;

    public RecyclerView recyclerView;
    LinearLayoutManager linearLayoutManager;

    private void initUI() {
        myActionBar = (MyActionBar) findViewById(R.id.MyActionBar);
        myActionBar.setLeftBimapAndTitle(null, "新建日常巡检");
        myActionBar.setBaseListennerLeft(new BaseListenner() {
            @Override
            public void onResult(Object result) {
                dismiss();
            }
        });
        appraise = (TextView) findViewById(R.id.appraise);
        appraise.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //开始答题
                MicrometerTable.getInstance().setTopicsRc(null);
                //MicrometerTable.getInstance().getTopicsRc();

                if (MicrometerTable.getInstance().getTopicsRc().size() > 0) {
                    //跳转日常表评分系统
                    MicrometerTableOSDialog2.getInstance(baseActivity);
//                    dismiss();
                } else {
                    if (MicrometerTable.getInstance().getHostoryRCTopics().size() > 0) {
                        MicrometerTableOSDialog2.getInstance(baseActivity);
                    } else {
                        baseActivity.SnackbarMake("无历史整改，请先添加题目", true, appraise);
                    }
                }


            }
        });

        recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
        linearLayoutManager = new LinearLayoutManager(baseActivity);
        recyclerView.setLayoutManager(linearLayoutManager);
        recyclerView.addItemDecoration(new RecyclerView.ItemDecoration() {
            @Override
            public void getItemOffsets(Rect outRect, int itemPosition, RecyclerView parent) {
                super.getItemOffsets(outRect, itemPosition, parent);
                if (itemPosition == 0 || itemPosition == (linearLayoutManager.getItemCount() - 1)) {
                    outRect.top = ProportionUtils.getInstance().adapterInt(25);
                }
            }
        });
    }

    private void adapterUI() {
//        ProportionUtils.getInstance().adapterView(findViewById(R.id.dialog_richang2_constraintLayout));
        ProportionUtils.getInstance().adapterScreen(baseActivity, findViewById(R.id.dialog_richang2_constraintLayout));
        ProportionUtils.getInstance().adapterTextView(appraise);
    }

    @Override
    protected void listener() {
        recyclerView.setAdapter(new RichangAdapter(MicrometerTable.getInstance().richangS));
    }

    public void RAapter() {
        recyclerView.setAdapter(new RichangAdapter(MicrometerTable.getInstance().richangS));
    }

    @Override
    protected void recycleView() {

    }
}
